package com.bana.fvs.controller;


import com.bana.sys.code.DatabaseResult;
import com.bana.fvs.dao.HolidayDAO;
import com.bana.fvs.model.Holiday;
import com.bana.sys.utils.ActionResult;
import com.bana.sys.utils.TokenRequest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 雾区假日方案
 */
@RestController
@RequestMapping(value = "/holiday", method = RequestMethod.POST)
public class HolidayController {

    @Resource
    private HolidayDAO holidayDAO;

    /**
     * 获取雾区假日方案集合
     * @param request wqbm
     * @return 方案集合
     */
    @RequestMapping(value = "/getHolidays.do", method = RequestMethod.POST)
    public List<Holiday> getHolidays(@RequestBody TokenRequest<Holiday> request) {
        return holidayDAO.getHolidays(request.getData().getWqbm());
    }

    /**
     * 新增雾区假日方案
     * @param request 假日方案
     * @return 操作结果
     */
    @RequestMapping(value = "/insertHoliday.do",method = RequestMethod.POST)
    public ActionResult insertHoliday(@RequestBody TokenRequest<Holiday> request){
        ActionResult actionResult = new ActionResult();
        holidayDAO.insertHoliday(request.getData());
        actionResult.setCzjg(DatabaseResult.Success);
        actionResult.setKey(request.getData().getFabm());
        return actionResult;
    }

    /**
     * 修改雾区假日方案
     * @param request 假日方案
     * @return
     */
    @RequestMapping(value = "/updateHoliday.do",method = RequestMethod.POST)
    public ActionResult updateHoliday(@RequestBody TokenRequest<Holiday> request){
        ActionResult actionResult = new ActionResult();
        holidayDAO.updateHoliday(request.getData());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }

    /**
     * 删除雾区假日方案
     *
     * @param request 假日方案
     * @return 操作结果
     */
    @RequestMapping(value = "/deleteHoliday.do", method = RequestMethod.POST)
    public ActionResult deleteHoliday(@RequestBody TokenRequest<Holiday> request) {
        ActionResult actionResult = new ActionResult();
        holidayDAO.deleteHoliday(request.getData().getFabm());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }

}
